﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
         class DataBesaHelp
    {

        private static string sql= "select * from specialty";

        private static string connS = "server=.;database=School;uid=sa;pwd=159357wqw";
        

        public static void PUI()
        {
            

            SqlConnection sqlConn = new SqlConnection(connS);

            SqlCommand cmd = new SqlCommand(connS, sqlConn);
            
            sqlConn.Open();

            var sdr = cmd.ExecuteReader();

            Console.WriteLine("{0}\t{1}\t\t{2}", "ID", "专业", "院系号");

            while (sdr.Read())
            {
                Console.WriteLine("{0}\t{1}\t\t{2}", sdr["Id"], sdr["specialty_Name"], sdr["department_Id"]);
            }

            sqlConn.Close();
        }


        public static void PUIA()
        {
            SqlDataAdapter dAdp = new SqlDataAdapter(sql, connS);

            DataTable dT = new DataTable();

            dAdp.Fill(dT);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("{0}\t{1}\t\t{2}", "ID", "专业", "院系号");

            for (int i = 0; i < dT.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t\t{2}", dT.Rows[i]["Id"], dT.Rows[i]["specialty_Name"], dT.Rows[i]["department_Id"]);
            }
        }



       
    }
}
